<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" href="zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="zTree/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="zTree/js/jquery.ztree.core-3.5.js"></script>
	
<script type="text/javascript">

	

	var setting = {
			data:{
				simpleData:{
					enable:true
				}
			} ,
	
			callback: {
				onClick: treeOnclick
			} 
	}
	
	var zNodes =[
	 			{ id:1, pId:0, name:"父节点1 - 展开", open:true},
	 			{ id:11, pId:1, name:"父节点11 - 折叠"},
	 			{ id:111, pId:11, name:"叶子节点111"},
	 			{ id:112, pId:11, name:"叶子节点112"},
	 			{ id:113, pId:11, name:"叶子节点113"},
	 			{ id:114, pId:11, name:"叶子节点114"},
	 			{ id:12, pId:1, name:"父节点12 - 折叠"},
	 			{ id:121, pId:12, name:"叶子节点121"},
	 			{ id:122, pId:12, name:"叶子节点122"},
	 			{ id:123, pId:12, name:"叶子节点123"},
	 			{ id:124, pId:12, name:"叶子节点124"},
	 			{ id:13, pId:1, name:"父节点13 - 没有子节点", isParent:true,},
	 			{ id:131, pId:13, name:"父节点131 -我看看13能展开不能", isParent:false},
	 			
	 			{ id:4, pId:0, name:"父节点4mao", open:true,isParent:false},
	 			{ id:41, pId:4, name:"41 isParent:false但是有子节点，强制转化为父节点", open:true,isParent:false},
	 			{ id:411, pId:41, name:"411", open:true},
	 			{ id:5, pId:0, name:"5我身上有click事件", open:true,isParent:true,click:"alert('点击我了');"},
	 			{id:6, pId:0, name:"6外部click", open:true,isParent:true,click:"tree6Click()"},
	 			{id:7, pId:0, name:"7试试onclick回掉函数", open:true,isParent:true}

	 			
	 		];

	
		
		
		var tree;
		
		function initTreeDemo1(){
			//alert(213);
			 tree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			//alert(demo1.getSelectedNodes());
		}
		
		function tree6Click(){
			alert("触发js");
		}
		
		function getSelected(){
			var selectedTree = tree.getSelectedNodes()[0];
			alert("触发js 获取selectedTree,id是："+selectedTree.id+",名字是："+selectedTree.name);
		}
		
		function treeOnclick(event, treeId, treeNode, clickFlag){
			alert("treeNode id是："+treeNode.id+",------名字是："+treeNode.name);
		}
		
</script>
	

</head>
<body>
<div class="content_wrap">
	<div class="zTreeDemoBackground left">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
	<input type="button" value="初始化数据" onclick="initTreeDemo1()">
	<input type="button" value="获取选中" onclick="getSelected()">
</div>

<p>
{ id:5, pId:0, name:"5我身上有click事件", open:true,isParent:true,click:"alert('点击我了');"}
<br>
click:"tree5Click()"
</p>


</body>
</html>